#include <vector>
#include <iostream>

using namespace std;

vector<int>isprime(41,1);

void backtrack(vector<int>& num, vector<vector<int>>& ans, vector<int>&temp, int i, int N)
{
    if(i == N)
    {
        if(isprime[1 + temp.back()])
            ans.push_back(temp);        
    }
    else
    {
        for(int k = 2;k <= N; k++){
            if(num[k] && isprime[k + temp.back()])
            {
                num[k] = 0;
                temp.push_back(k);
                backtrack(num, ans, temp, i+1, N); 
                temp.pop_back();     
                num[k] = 1;          
            }
        }
    }
}
int main()
{  
   
    for(int i=2;i<=41;i++)
        if(isprime[i])
        {
            if(i * i < 41)
                for(int j = i*i;j<41;j+=i)
                    isprime[j] = 0;
        }

    int N;int c = 0;
    while(cin >> N)
    {
        vector<int>num(N+1,1);
        vector<vector<int>> ans;
        vector<int>temp{1};
        backtrack(num, ans, temp, 1, N);
        printf("Case %d:\n", ++c);
        for(auto& v : ans)
        {
            cout << "1";
            for(int i = 1;i<N;i++)
                cout << " "<<v[i];
            cout <<endl;
        }
        cout <<endl;

    }
    return 0;
}
